from d4.models import D4Dic
from d4.serializers import D4DicSerializer
from d4.serializers.filters import DicFilter
from d4.permissions import IsOwnerOrReadOnly
from d4.throttling import CustomThrottle
from rest_framework.viewsets import ModelViewSet
# from rest_framework.filters import OrderingFilter
# from rest_framework.response import Response
# from rest_framework.decorators import action
from rest_framework.throttling import AnonRateThrottle,UserRateThrottle
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from d4.serializers.pagination import PageNumberPagination2

class DicGVS(ModelViewSet):
    '''
    CBV下的系统字典管理API
    '''
    queryset = D4Dic.objects.all()
    serializer_class = D4DicSerializer
    permission_classes = (IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly)
    # 也可以在类中配置排序组件，可以在视图中代替或覆盖全局配置
    # filter_backends = [OrderingFilter]
    # 配置排序字段
    ordering_fields = ['name', 'code']
    # 设置分页器, 可以在视图中代替或覆盖全局设置
    # pagination_class = PageNumberPagination2
    # 限流自定义限流类
    throttle_classes = [AnonRateThrottle]
